package org.jeecgframework.web.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.jeecgframework.core.util.ContextHolderUtils;
import org.junit.Test;

public class UtilQrCode {

    private static final int BLACK = 0xff000000;
    private static final int WHITE = 0xFFFFFFFF;

    /**
     * 生成文件
     *
     * @param msg  二维码
     * @param path 二维码的路径，包括文件名及后缀
     * @return
     */
    public static File generateFile(String msg, String path) {

        HttpServletRequest request = ContextHolderUtils.getRequest();
        String ctxPath = request.getSession().getServletContext().getRealPath("");
        File file = new File(path);
        try {
            String filePostfix = "png";
            // 依次为内容(不支持中文),宽,长,中间图标路径,储存路径
            LogoConfig.encode(msg, 512, 512, ctxPath + "/plug-in/login/images/qrlogo.png", file);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return file;
    }

}
